<?php
include('conect.php');

//connection String
$con = mysql_connect($hostname, $username, $password) or die('Could not connect: ' . mysql_error());
//select database
mysql_select_db($database, $con);

mysql_query("SET NAMES utf8");

if ($_GET['acction'] === 'tree') {
$query = "SELECT id,task,iconCls FROM pro WHERE user='".$_GET['UserID']."'";
$rs = mysql_query($query);

$cild = array();
$cild1 = array();
$parent = array();
while($obj = mysql_fetch_object($rs)) {
	$query1 = "SELECT id,task,iconCls,tip FROM subpro WHERE pro='".$obj->id."'";
	$rs1 = mysql_query($query1);
	while($obj1 = mysql_fetch_object($rs1)) {
		$query2 = "SELECT id,task,iconCls,leaf FROM cild WHERE subpro='".$obj1->id."'";
		$rs2 = mysql_query($query2);
		$cild = array();
		while($obj2 = mysql_fetch_object($rs2)) {
			$cild[] = $obj2;
		}
		
		$cild1[] = array(
    		'task' => $obj1->task, 
    		'idd'   => $obj1->id,
    		'tip'   => $obj1->tip,
    		'iconCls'   => 'task-folder',
    		'expanded'   => true,
    		'children'  => $cild
			);
	}
	$parent[] = array(
    	'task' => $obj->task, 
    	'iddd'   => $obj->id,
    	//'proid'   => $obj->id,
    	'iconCls'   => $obj->iconCls, //'task-folder',
    	'expanded'   => true,
    	'children'  => $cild1
	);
	$cild1 = array();
}
$arr = array(
	'text' => '.',
	'children'  => $parent
);
}
if ($_GET['acction'] === 'treee') {
$cild = array();
$cild1 = array();
$parent = array();
$query = "SELECT id,task,iconCls FROM pro WHERE root='".$_GET['id']."'";
$rs = mysql_query($query);

while($obj = mysql_fetch_object($rs)) {
	$query1 = "SELECT id,task,iconCls FROM subpro WHERE pro='".$obj->id."'";
	$rs1 = mysql_query($query1);
	while($obj1 = mysql_fetch_object($rs1)) {
		$query2 = "SELECT it,task,iconCls,leaf FROM cild WHERE subpro='".$obj1->id."'";
		$rs2 = mysql_query($query2);
		$cild = array();
		while($obj2 = mysql_fetch_object($rs2)) {
			$cild[] = $obj2;
		}
		
		$cild1[] = array(
    		'task' => $obj1->task, 
    		'itt'   => $obj1->id,
    		//'parentid'   => $obj1->id,
    		'iconCls'   => 'task-folder',
    		'expanded'   => true,
    		'children'  => $cild
			);
	}
	$cild = array();
	$parent[] = array(
    	'task' => $obj->task, 
    	'ittt'   => $obj->id,
    	//'proid'   => $obj->id,
    	'iconCls'   => $obj->iconCls,
    	'expanded'   => true,
    	'children'  => $cild1
	);
	$cild1 = array();
}
$arr = array(
	'text' => '.',
	'children'  => $parent //$temp
);
}

mysql_close($con);
echo json_encode($arr);

?>